package com.yunkeji.common.enums.app;

import com.yunkeji.common.exception.AppServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 用户会员类型
 *
 * @author yunkeji
 */
@Getter
@AllArgsConstructor
public enum AppUserVipType {

    普通会员(211),
    专属会员(213);
    private final Integer code;

    public static AppUserVipType getByCode(Integer code) {
        AppUserVipType[] values = AppUserVipType.values();
        Optional<AppUserVipType> first =
            Arrays.stream(values).filter(item -> item.getCode().equals(code)).findFirst();
        if (first.isPresent()) {
            return first.get();
        } else {
            throw AppServiceException.paramException("用户会员类型参数异常");
        }
    }
}
